package com.qf.listener;


import com.qf.pojo.TbGoodsType;
import com.qf.service.GoodsTypeService;
import com.qf.service.impl.GoodsTypeServiceImpl;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.util.List;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/8/17 10:36
 */
@WebListener
public class MyContextListener implements ServletContextListener {

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        GoodsTypeService goodsService=new GoodsTypeServiceImpl();
        List<TbGoodsType> tbGoodsType=goodsService.findALL(1);
        ServletContext servletContext = servletContextEvent.getServletContext();
        System.out.println("tbGoodsType = " + tbGoodsType);
        servletContext.setAttribute("goodsType", tbGoodsType);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        servletContextEvent.getServletContext().removeAttribute("goodsType");
    }
}
